<template>
  <div class="app-container">
    <el-form ref="form" :model="card" label-width="120px">
      <el-form-item label="学生姓名">
        <el-input v-model="student.sname" />
      </el-form-item>
      <el-form-item label="卡状态">
        <el-input v-model="card.state" />
      </el-form-item>
      <el-form-item label="剩余借书数量">
        <el-input v-model="card.number" />
      </el-form-item>
      <el-form-item label="办卡日期">
        <el-date-picker
          v-model="card.date"
          type="date"
          placeholder="请选择时间"
          value-format="yyyy-MM-dd"
          style="width: 100%"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary"  @click="onSubmit">新增学生借阅卡</el-button>
        <el-button @click="onCancel">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import request from '@/utils/request'
export default {
  data() {
    return {
      card: {
        sid: '',
        sname: '',
        state: '',
        number: '',
        date: ''
      },
      student:{
        sname:''
      }
    }
  },
  methods: {
    onSubmit() {
      request({
          url: "/edu/student/selectIdByName.do?name=" + this.student.sname,
          method: "GET"
        }
      ).then(res => {
        if (res.code == 0) {
          if (res.data != null) {
            this.card.sid = res.data.id;

            // 请求接口 实现用户新增接口的调用
            request({
              url: "/library/card/save.do",
              method: "POST",
              data: this.card
            }).then(res => {
              if (res.code == 0) {
                //跳转到列表页面
                this.$router.push("/cardlist");
              }
            })
          }
        }
      })
    },
      // 请求接口 实现用户新增接口的调用
    onCancel() {
      this.$message({
        message: '取消新增卡',
        type: 'warning'
      })
    }
  }
}
</script>

<style scoped>
.line{
  text-align: center;
}
</style>

